'use strict';

const Controller = require('egg').Controller;

class ProductController extends Controller {
  async getproducts () {
    const data = this.ctx.query;
    console.log(data);
    const { ctx } = this;

    const res = await ctx.service.products.getproducts(data);
    ctx.body = res;
  }
  async getorderproduct () {
    const data = this.ctx.query;
    console.log(data);
    const { ctx } = this;
    // if (Object.prototype.isPrototypeOf(data) && Object.keys(data).length === 0) {
    //   ctx.body = '登录失败';
    //   // return '登录失败';
    // } else {
    //   const res = await ctx.service.login.login(data);
    //   ctx.body = res;
    // }
    const res = await ctx.service.products.getorderproduct(data);
    ctx.body = res;
  }
  async postproduct () {
    const { ctx } = this;
    const data = ctx.request.body;
    const res = await ctx.service.products.postproduct(data);
    ctx.body = res;
  }
  // get获取我的发布
  async getmysend () {
    const data = this.ctx.query;
    console.log(data);
    const { ctx } = this;
    const res = await ctx.service.products.getmysend(data);
    ctx.body = res;
  }
  // post修改发布舱位
  async updateproduct () {
    const { ctx } = this;
    const data = ctx.request.body;
    const res = await ctx.service.products.updateproduct(data);
    ctx.body = res;
  }
  // get获取我的发布
  async delproduct () {
    const data = this.ctx.query;
    const { ctx } = this;
    const res = await ctx.service.products.delproduct(data);
    ctx.body = res;
  }

}

module.exports = ProductController;
